package com.ls.fw.data.utils;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;

import com.ls.fw.data.bean.KeyValue;

public class DataUtil {
	
	
	/**
	 * 获取泛型
	 * 
	 * @author lisheng
	 * @date 2014年12月31日 下午7:09:44
	 * @version V1.0
	 * @param cla
	 * @return
	 */
	public static Class getGenerricType(Class cla){
		Class type = null;
		Type t = cla.getGenericSuperclass();
		if (t instanceof ParameterizedType) {
			Type[] p = ((ParameterizedType) t).getActualTypeArguments();
			try {
				type = (Class) p[0];
			} catch (Exception e) {
			}
		}
		return type;
	}
	
	public static String joiner(List<KeyValue> lists, String oper) {
		
		if (lists == null || lists.size() == 0) {
			return "";
		}

		StringBuilder sb = new StringBuilder(lists.get(0).toString());
		for (int i = 1; i < lists.size(); i++) {
			sb.append(oper);
			sb.append(lists.get(i).toString());
		}

		return sb.toString();
	}

	public static List<Map<String, Object>> sortByMap(List<Map<String, Object>> lists) {

		return lists;
	}


	public static double[] String2DoubleArr(String paramer) {
		String[] split = paramer.split(",");
		double[] ds = new double[split.length];
		for (int i = 0; i < ds.length; i++) {
			ds[i] = Double.parseDouble(split[i].trim());
		}
		return ds;
	}

	public static double[] KV2DoubleArr(List<KeyValue> params) {
		double[] ds = new double[params.size()];
		int i = 0;
		for (KeyValue v : params) {
			ds[i] = ((Number) v.value).doubleValue();
			i++;
		}
		return ds;
	}

}
